package me.sauce.dntest;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Toast;

import me.sauce.dntest.data.TimerModelHelper;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
　　TelephonyManager telephonyManager = (TelephonyManager) this
　　.getSystemService(Context.TELEPHONY_SERVICE);
　　String IMEI = telephonyManager.getDeviceId();

        findViewById(R.id.open).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    if (!Settings.canDrawOverlays(getApplicationContext())) {
                        Toast.makeText(MainActivity.this, "没设置权限还想用？", Toast.LENGTH_SHORT).show();
                    }
                } else {

                    Intent intent = new Intent(MainActivity.this, FxService.class);
                    startService(intent);
                }
            }
        });
        findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, FxService.class);
                stopService(intent);
            }
        });
        findViewById(R.id.permission).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    if (!Settings.canDrawOverlays(getApplicationContext())) {
                        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                        startActivity(intent);
                    } else {
                        Toast.makeText(MainActivity.this, "都设置完了还点屁", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(MainActivity.this, "系统版本太低了，根本不用设置", Toast.LENGTH_SHORT).show();
                }
            }
        });
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        TimerListAdapter timerListAdapter = new TimerListAdapter(new TimerListAdapter.onItemClick() {
            @Override
            public void onClick(long id) {
            }
        });
        recyclerView.setAdapter(timerListAdapter);
        timerListAdapter.setTimerModelList(TimerModelHelper.getInstance().getAllData());
    }
    private void initDialog(){
        new AlertDialog.Builder(this).setView()
    }
}
